<?php

namespace hiduoke\services\formBuilder\traits;

use hiduoke\services\formBuilder\form\DkFileInput;
use hiduoke\services\formBuilder\form\DkFileListInput;
use hiduoke\services\formBuilder\form\DkUpload;

trait DkFile
{
    /**
     * 选择一个文件
     * @param $field
     * @param $title
     * @param string $value
     * @param int $type 1图片 2音频 3视频
     * @return DkFileInput
     */
    public static function dkFile($field, $title, $value = '', $type = 0)
    {
        $component = new DkFileInput($field, $title, $value);
        $input = $component->props(['type' => $type]);
        return $input;
    }

    /**
     * 选择一个图片
     * @param $field
     * @param $title
     * @param string $value
     * @return DkFileInput
     */
    public static function dkImage($field, $title, $value = '')
    {
        return self::dkFile($field, $title, $value, 1);
    }

    /**
     * 选择一个音频
     * @param $field
     * @param $title
     * @param string $value
     * @return DkFileInput
     */
    public static function dkAudio($field, $title, $value = '')
    {
        return self::dkFile($field, $title, $value, 2);
    }

    /**
     * 选择一个视频
     * @param $field
     * @param $title
     * @param string $value
     * @return DkFileInput
     */
    public static function dkVideo($field, $title, $value = '')
    {
        return self::dkFile($field, $title, $value, 3);
    }

    /**
     * 选择多个文件
     * @param $field
     * @param $title
     * @param array $value
     * @param int $type 1图片 2音频 3视频
     * @return DkFileListInput
     */
    public static function dkFileList($field, $title, array $value = [], $type = 0)
    {
        $component = new DkFileListInput($field, $title, $value);
        $input = $component->props(['type' => $type]);
        return $input;
    }

    /**
     * 选择多个图片
     * @param $field
     * @param $title
     * @param array $value
     * @return DkFileListInput
     */
    public static function dkImageList($field, $title, array $value = [])
    {
        return self::dkFileList($field, $title, $value, 1);
    }

    /**
     * 选择多个音频
     * @param $field
     * @param $title
     * @param array $value
     * @return DkFileListInput
     */
    public static function dkAudioList($field, $title, array $value = [])
    {
        return self::dkFileList($field, $title, $value, 2);
    }

    /**
     * 选择多个视频
     * @param $field
     * @param $title
     * @param array $value
     * @return DkFileListInput
     */
    public static function dkVideoList($field, $title, array $value = [])
    {
        return self::dkFileList($field, $title, $value, 3);
    }


    public static function dkUpload($field, $title, array $value = []){
        $component = new DkUpload($field, $title, $value);
        $input = $component->props([]);
        return $input;
    }
}
